package com.seio.edc.console;

import com.nova.edc.model.energy.Gather;
import com.nova.edc.model.energy.GatherSummary;
import com.nova.edc.model.energy.OverallStatistics;
import com.nova.edc.model.system.AreaPoint;
import com.nova.edc.model.system.CustomerInfo;
import com.nova.edc.model.system.ModelConstant;
import com.nova.edc.service.energy.GatherService;
import com.nova.edc.service.energy.GatherSummaryService;
import com.nova.edc.service.energy.OverallStatisticsService;
import com.nova.edc.service.system.AreaPointService;
import com.nova.edc.service.system.CustomerInfoService;
import com.nova.frame.utils.DateUtils;
import com.seio.edc.util.DateTimeUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/3/4 0004.
 */
public class DataStatistics {
    private Log log = LogFactory.getLog(Gather.class);
    @Autowired
    private GatherService novaGatherService;
    @Autowired
    private GatherSummaryService novaGatherSummaryService;
    @Autowired
    private AreaPointService novaAreaPointService;
    @Autowired
    private OverallStatisticsService novaOverallStatisticsService;
    @Autowired
    private CustomerInfoService novaCustomerInfoService;

    public void execute() {
        log.info("节点工作状况日结开始" + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
        List<AreaPoint> areaPoints = novaAreaPointService.findAll();
        novaGatherService.insertData(DateUtils.getDate2SStr(DateUtils.getYesterdayDate()) + " 00:00:00", DateUtils.getDate2SStr(DateUtils.getYesterdayDate()) + " 23:59:59", areaPoints);
        List<GatherSummary> list = novaGatherSummaryService.findStateTime(ModelConstant.LIGHT_ON, DateUtils.getDate2SStr(DateUtils.getYesterdayDate()));
        novaGatherSummaryService.insertList(list);
        log.info("节点工作状况日结结束" + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
    }

    public void executeOverAll(){
        log.info("公司日结开始" + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
        List<CustomerInfo> customerInfoList = novaCustomerInfoService.findAllCustomerInfo();
        List<OverallStatistics> overallStatisticses = novaOverallStatisticsService.getStatistics(customerInfoList, DateUtils.getDate2SStr(DateUtils.getYesterdayDate()));
       novaOverallStatisticsService.insert(overallStatisticses);
        log.info("公司日结结束" + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
    }
}
